﻿Public Class PROMOTIONLIST
    Dim connect As CONDB = CONDB.NewConnection()
    Dim PROVIDER_Check As New PROVIDERSCLASS

    Private Sub MTRGTIDTxt_Click(sender As Object, e As EventArgs) Handles MTRGTIDTxt.Click
        MTRGTIDTxt.Text = ""
    End Sub

    Private Sub STRGTIDTxt_Click(sender As Object, e As EventArgs) Handles STRGTIDTxt.Click
        STRGTIDTxt.Text = ""
    End Sub

    Private Sub SBRGTIDTxt_Click(sender As Object, e As EventArgs) Handles SBRGTIDTxt.Click
        SBRGTIDTxt.Text = ""
    End Sub

    Private Sub PROMOTxt_Click(sender As Object, e As EventArgs) Handles PROMOTxt.Click
        PROMOTxt.Text = ""
    End Sub

    Private Sub PROMOTIONLIST_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim objSelectMaspromotion As New maspromotion
        Dim maspromotionData As DataTable
        maspromotionData = connect.GetTable(objSelectMaspromotion.selectMaspromotion_)
        'masgrpdrgData = connectlocal.GetTable(objSelectDataMasgrpdrg.selectMasgrpdrg_)
        maspromotionGrid.PrimaryGrid.DataSource = maspromotionData
        Dim d As New FriendsDate
        d.TO_TH()
        d.culTure_TH()

        Dim objSelectProoncontact As New prooncontact
        Dim prooncontactData As DataTable
        prooncontactData = connect.GetTable(objSelectProoncontact.selectProoncontact_)
        'masgrpdrgData = connectlocal.GetTable(objSelectDataMasgrpdrg.selectMasgrpdrg_)
        prooncontactGrid.PrimaryGrid.DataSource = prooncontactData

        Dim s As FILTERCLASS
        Dim sql As String = "SELECT CAST(MTRGTID AS CHAR(4)) AS MTRGTID, MTRGTNAME, SDET FROM masmtypergt WHERE STATUS = '1'"
        s = New FILTERCLASS(MTRGTIDTxt, sql, "รหัสหมวดคู่สัญญา,ชื่อหมวดคู่สัญญา", "50,160", "1,1", "1,1")
        's.SetShowInDown = False
        s.SetShowBorder = True

        Dim s5 As FILTERCLASS
        Dim sql5 As String = "SELECT CAST(PROID AS CHAR(4)) AS PROID, PRONAME FROM maspromotion WHERE STATUS = '1'"
        s5 = New FILTERCLASS(PROMOTxt, sql5, "รหัสโปรโมชั่น,ชื่อโปรโมชั่น", "50,160", "1,1", "1,1")
        's.SetShowInDown = False
        s5.SetShowBorder = True

        DesignForm(Me)
        DesignGrid(maspromotionGrid)
        DesignGrid(prooncontactGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub MTRGTIDTxt_TextChanged(sender As Object, e As EventArgs) Handles MTRGTIDTxt.TextChanged
        STRGTIDTxt.Enabled = True

        Dim s2 As FILTERCLASS
        Dim sql2 As String = "SELECT CAST(STRGTID AS CHAR(4)) AS STRGTID, STRGTNAME FROM masstypergt WHERE STATUS = '1' AND MTRGTID = '" & MTRGTIDTxt.Tag & "'"
        s2 = New FILTERCLASS(STRGTIDTxt, sql2, "รหัสกลุ่มคู่สัญญา,ชื่อกลุ่มคู่สัญญา", "50,160", "1,1", "1,1")
        's.SetShowInDown = False
        s2.SetShowBorder = True
    End Sub

    Private Sub STRGTIDTxt_TextChanged(sender As Object, e As EventArgs) Handles STRGTIDTxt.TextChanged
        SBRGTIDTxt.Enabled = True

        Dim s3 As FILTERCLASS
        Dim sql3 As String = "SELECT CAST(SBRGTID AS CHAR(4)) AS SBRGTID, SUBRGTNAME FROM massubrgt WHERE STATUS = '1' AND STRGTID = '" & STRGTIDTxt.Tag & "'"
        s3 = New FILTERCLASS(SBRGTIDTxt, sql3, "รหัสกลุ่มคู่สัญญา,ชื่อกลุ่มคู่สัญญา", "50,160", "1,1", "1,1")
        's.SetShowInDown = False
        s3.SetShowBorder = True
    End Sub

    Private Sub maspromotionGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles maspromotionGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        'f.TXT_CID.Text = grid.Cells.Item(2).Value
        PROIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสโปรโมชั่น").Value()
        PRONAMETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อโปรโมชั่น").Value()
        maspromotionREMARKTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("คำอธิบาย").Value()

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("วันที่เริ่มต้นโปรโมชั่น").Value().ToString.Length > 0 Then
            STDATEDate.Value = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("วันที่เริ่มต้นโปรโมชั่น").Value()
        Else
            STDATEDate.Value = Nothing
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("วันที่สิ้นสุดโปรโมชั่น").Value().ToString.Length > 0 Then
            If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("วันที่สิ้นสุดโปรโมชั่น").Value() = "9999-09-09" Then
                noENDATE.Visible = True
                ENDATEDate.Checked = False
            Else
                noENDATE.Visible = False
                ENDATEDate.Value = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("วันที่สิ้นสุดโปรโมชั่น").Value()
                ENDATEDate.Checked = True
            End If
        Else
            ENDATEDate.Value = Nothing
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            maspromotionStatusChk.Checked = True
        Else
            maspromotionStatusChk.Checked = False
        End If

        Dim objChkboxUpdate As New CLICKGRIDCHECKBOX
        objChkboxUpdate.clickChkboxUpdate("maspromotion", CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value(), "STATUS", "PROID", PROIDTxt.Text)

        Dim s5 As FILTERCLASS
        Dim sql5 As String = "SELECT CAST(PROID AS CHAR(4)) AS PROID, PRONAME FROM maspromotion WHERE STATUS = '1'"
        s5 = New FILTERCLASS(PROMOTxt, sql5, "รหัสโปรโมชั่น,ชื่อโปรโมชั่น", "50,160", "1,1", "1,1")
        's.SetShowInDown = False
        s5.SetShowBorder = True
    End Sub

    Private Sub prooncontactGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles prooncontactGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        'f.TXT_CID.Text = grid.Cells.Item(2).Value
        POCIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสการผูกโปรโมชั่น").Value()
        MTRGTIDTxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสหมวดคู่สัญญา").Value()
        MTRGTIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อหมวดคู่สัญญา").Value()

        Try
            STRGTIDTxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสกลุ่มคู่สัญญา").Value()
            STRGTIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อกลุ่มคู่สัญญา").Value()
        Catch ex As Exception
            STRGTIDTxt.Tag = ""
            STRGTIDTxt.Text = ""
        End Try

        Try
            SBRGTIDTxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสสิทธิ์").Value()
            SBRGTIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อสิทธิ์").Value()
        Catch ex As Exception
            SBRGTIDTxt.Tag = ""
            SBRGTIDTxt.Text = ""
        End Try
        
        PROMOTxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสโปรโมชั่น").Value()
        PROMOTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อโปรโมชั่น").Value()

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            prooncontactStatusChk.Checked = True
        Else
            prooncontactStatusChk.Checked = False
        End If

        Dim objChkboxUpdate As New CLICKGRIDCHECKBOX
        objChkboxUpdate.clickChkboxUpdate("prooncontact", CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value(), "STATUS", "POCID", POCIDTxt.Text)
    End Sub

    Private Sub addMaspromotion_Click(sender As Object, e As EventArgs) Handles addMaspromotion.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If PRONAMETxt.Text.ToString.Length > 0 Then
                    If ENDATEDate.Checked = True Then
                        If STDATEDate.Value <= ENDATEDate.Value Then
                            Dim objInsertData As New maspromotion
                            objInsertData.PRONAME_ = PRONAMETxt.Text
                            objInsertData.REMARK_ = maspromotionREMARKTxt.Text
                            Dim startDay As String = STDATEDate.Value.Day
                            Dim startMonth As String = STDATEDate.Value.Month
                            Dim startYear As String = STDATEDate.Value.Year
                            objInsertData.STDATE_ = startYear & "-" & startMonth & "-" & startDay
                            Dim endDay As String = ENDATEDate.Value.Day
                            Dim endMonth As String = ENDATEDate.Value.Month
                            Dim endYear As String = ENDATEDate.Value.Year
                            objInsertData.ENDATE_ = endYear & "-" & endMonth & "-" & endDay
                            objInsertData.STATUS_ = maspromotionStatusChk.Checked
                            objInsertData.insertMaspromotionData()
                        Else
                            MsgBox("โปรดกรุณาระบุวันที่เริ่มต้นให้ถึงก่อนวันที่สิ้นสุด")
                        End If
                    Else
                        Dim objInsertData As New maspromotion
                        objInsertData.PRONAME_ = PRONAMETxt.Text
                        objInsertData.REMARK_ = maspromotionREMARKTxt.Text
                        Dim startDay As String = STDATEDate.Value.Day
                        Dim startMonth As String = STDATEDate.Value.Month
                        Dim startYear As String = STDATEDate.Value.Year
                        objInsertData.STDATE_ = startYear & "-" & startMonth & "-" & startDay
                        objInsertData.ENDATE_ = "9456-09-09"
                        objInsertData.STATUS_ = maspromotionStatusChk.Checked
                        objInsertData.insertMaspromotionData()
                    End If

                    Dim objSelectMaspromotion As New maspromotion
                    Dim maspromotionData As DataTable
                    maspromotionData = connect.GetTable(objSelectMaspromotion.selectMaspromotion_)
                    'masgrpdrgData = connectlocal.GetTable(objSelectDataMasgrpdrg.selectMasgrpdrg_)
                    maspromotionGrid.PrimaryGrid.DataSource = maspromotionData

                    Dim s5 As FILTERCLASS
                    Dim sql5 As String = "SELECT CAST(PROID AS CHAR(4)) AS PROID, PRONAME FROM maspromotion WHERE STATUS = '1'"
                    s5 = New FILTERCLASS(PROMOTxt, sql5, "รหัสโปรโมชั่น,ชื่อโปรโมชั่น", "50,160", "1,1", "1,1")
                    's.SetShowInDown = False
                    s5.SetShowBorder = True

                    PROIDTxt.Text = ""
                    PRONAMETxt.Text = ""
                    maspromotionREMARKTxt.Text = ""
                    STDATEDate.Checked = False
                    ENDATEDate.Checked = False
                    maspromotionStatusChk.Checked = False
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editMaspromotion_Click(sender As Object, e As EventArgs) Handles editMaspromotion.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If PRONAMETxt.Text.ToString.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลโปรโมชั่นดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                    If editStat = 1 Then
                        If ENDATEDate.Checked = True Then
                            If STDATEDate.Value <= ENDATEDate.Value Then
                                Dim objEditData As New maspromotion
                                objEditData.PROID_ = PROIDTxt.Text
                                objEditData.PRONAME_ = PRONAMETxt.Text
                                objEditData.REMARK_ = maspromotionREMARKTxt.Text
                                Dim startDay As String = STDATEDate.Value.Day
                                Dim startMonth As String = STDATEDate.Value.Month
                                Dim startYear As String = STDATEDate.Value.Year
                                objEditData.STDATE_ = startYear & "-" & startMonth & "-" & startDay
                                Dim endDay As String = ENDATEDate.Value.Day
                                Dim endMonth As String = ENDATEDate.Value.Month
                                Dim endYear As String = ENDATEDate.Value.Year
                                objEditData.ENDATE_ = endYear & "-" & endMonth & "-" & endDay
                                objEditData.STATUS_ = maspromotionStatusChk.Checked
                                objEditData.editMaspromotionData()
                            Else
                                MsgBox("โปรดกรุณาระบุวันที่เริ่มต้นให้ถึงก่อนวันที่สิ้นสุด")
                            End If
                        Else
                            Dim objEditData As New maspromotion
                            objEditData.PROID_ = PROIDTxt.Text
                            objEditData.PRONAME_ = PRONAMETxt.Text
                            objEditData.REMARK_ = maspromotionREMARKTxt.Text
                            Dim startDay As String = STDATEDate.Value.Day
                            Dim startMonth As String = STDATEDate.Value.Month
                            Dim startYear As String = STDATEDate.Value.Year
                            objEditData.STDATE_ = startYear & "-" & startMonth & "-" & startDay
                            objEditData.ENDATE_ = "9456-09-09"
                            objEditData.STATUS_ = maspromotionStatusChk.Checked
                            objEditData.editMaspromotionData()
                        End If

                        Dim objSelectMaspromotion As New maspromotion
                        Dim maspromotionData As DataTable
                        maspromotionData = connect.GetTable(objSelectMaspromotion.selectMaspromotion_)
                        'masgrpdrgData = connectlocal.GetTable(objSelectDataMasgrpdrg.selectMasgrpdrg_)
                        maspromotionGrid.PrimaryGrid.DataSource = maspromotionData

                        Dim s5 As FILTERCLASS
                        Dim sql5 As String = "SELECT CAST(PROID AS CHAR(4)) AS PROID, PRONAME FROM maspromotion WHERE STATUS = '1'"
                        s5 = New FILTERCLASS(PROMOTxt, sql5, "รหัสโปรโมชั่น,ชื่อโปรโมชั่น", "50,160", "1,1", "1,1")
                        's.SetShowInDown = False
                        s5.SetShowBorder = True

                        PROIDTxt.Text = ""
                        PRONAMETxt.Text = ""
                        maspromotionREMARKTxt.Text = ""
                        STDATEDate.Checked = False
                        ENDATEDate.Checked = False
                        maspromotionStatusChk.Checked = False
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub addProoncontact_Click(sender As Object, e As EventArgs) Handles addProoncontact.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If MTRGTIDTxt.Text.ToString.Length > 0 And PROMOTxt.Text.ToString.Length > 0 Then
                    Dim objInsertData As New prooncontact
                    objInsertData.MTRGTID_ = MTRGTIDTxt.Tag
                    objInsertData.STRGTID_ = STRGTIDTxt.Tag
                    objInsertData.SBRGTID_ = SBRGTIDTxt.Tag
                    objInsertData.PROID_ = PROMOTxt.Tag
                    objInsertData.STATUS_ = prooncontactStatusChk.Checked
                    objInsertData.insertProoncontactData()

                    Dim objSelectProoncontact As New prooncontact
                    Dim prooncontactData As DataTable
                    prooncontactData = connect.GetTable(objSelectProoncontact.selectProoncontact_)
                    'masgrpdrgData = connectlocal.GetTable(objSelectDataMasgrpdrg.selectMasgrpdrg_)
                    prooncontactGrid.PrimaryGrid.DataSource = prooncontactData

                    prooncontactStatusChk.Checked = False
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editProoncontact_Click(sender As Object, e As EventArgs) Handles editProoncontact.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If MTRGTIDTxt.Text.ToString.Length > 0 And PROMOTxt.Text.ToString.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขการผูกสิทธิ์และโปรโมชั่นดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                    If editStat = 1 Then
                        Dim objEditData As New prooncontact
                        objEditData.POCID_ = POCIDTxt.Text
                        objEditData.MTRGTID_ = MTRGTIDTxt.Tag
                        objEditData.STRGTID_ = STRGTIDTxt.Tag
                        objEditData.SBRGTID_ = SBRGTIDTxt.Tag
                        objEditData.PROID_ = PROMOTxt.Tag
                        objEditData.STATUS_ = prooncontactStatusChk.Checked
                        objEditData.editProoncontactData()

                        Dim objSelectProoncontact As New prooncontact
                        Dim prooncontactData As DataTable
                        prooncontactData = connect.GetTable(objSelectProoncontact.selectProoncontact_)
                        'masgrpdrgData = connectlocal.GetTable(objSelectDataMasgrpdrg.selectMasgrpdrg_)
                        prooncontactGrid.PrimaryGrid.DataSource = prooncontactData

                        prooncontactStatusChk.Checked = False
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    
   
End Class